package Mutation;

import GA.Chromosome;
import GA.Gene;
import GA.Mutation;

public class SwapMutation extends Mutation {

	public SwapMutation(double mutationProb) {
		super(mutationProb);
	}

	protected Chromosome mutate(Chromosome chrom) {
		// Selects 2 random points
		int x = GA.Algorithm.random.nextInt(chrom.getChromosomeLenght());
		int y = GA.Algorithm.random.nextInt(chrom.getChromosomeLenght());
		// Swap elements
		Gene aux = chrom.getGene(y);
		chrom.setGene(y, chrom.getGene(x));
		chrom.setGene(x, aux);
		return chrom;
	}

}
